using System.Collections.Generic;
using Valil;
using Valil.Chess;
using Move = ChessKit.ChessLogic.Move;

namespace UnitTests.Env
{
	public class ValilBoardDriver : ITestBoard
	{
		private readonly Game _game;

		public ValilBoardDriver()
		{
			var p = new GameStringDescriptionProxy { Model = new Game() };
			p.LoadNewGame();
			_game = p.Model;
		}
		public IEnumerable<Move> GetAllLegalMoves()
		{
			foreach (var m in _game.PossibleMoves)
			{
				var insert = Utils.GetCAN(m).Insert(2, "-") + "=Q";
				//		    if (m is PromotionMove) insert += "=Q";
				yield return Move.Parse(insert);
			}
		}

		public void MakeMove(Move move)
		{
			_game.Make(GetValilMove(move));
		}

		private Valil.Chess.Moves.Move GetValilMove(Move move)
		{
			return Utils.GetCANMove(_game, move.ToString().Replace("-", ""));
		}

		public string Fen { get { return Utils.GetFEN(_game.CurrentBoard); } }
		public string GetSan(Move move)
		{
			var m = GetValilMove(move);
			return Utils.GetSANBegin(_game, m)/* + Utils.GetSANEnd(_game, m)*/;
		}
	}
}